/* Simple EDC exemplifying how to receive and emit all types of messages */

/* Actually for sets it will send back a message of the same type with the
 * first item and N other messages with the remaining items. */

collections {
   group {
      name: "messages_echo";

      parts {
         part {
            name: "bg";
            type: RECT;
            description {
               state: "default" 0.0;
               min: 400 50;
               max: 400 50;
               color: 0 0 0 255;
            }
         }

         part {
            name: "text";
            type: TEXT;
            description {
               state: "default" 0.0;
               color: 255 255 255 255;
               text {
                  font: "Sans";
                  size: 20;
                  text: "I will echo all your messages ;)";
               }
            }
         }
      }

      script {
         public message(Msg_Type:type, id, ...) {
            if (type == MSG_INT)
               send_message(type, id, getarg(2));
            else if (type == MSG_FLOAT)
               send_message(type, id, getfarg(2));
            else if (type == MSG_STRING) {
               new buf[1024];
               getsarg(2, buf, sizeof(buf));
               send_message(type, id, buf);
            }
            else if (type == MSG_STRING_INT) {
               new buf[1024];
               getsarg(2, buf, sizeof(buf));
               send_message(type, id, buf, getarg(3));
            }
            else if (type == MSG_STRING_FLOAT) {
               new buf[1024];
               getsarg(2, buf, sizeof(buf));
               send_message(type, id, buf, getfarg(3));
            }
            else if (type == MSG_INT_SET) {
               new i, n = numargs();
               send_message(type, id, getarg(2));
               for (i = 3; i < n; i++)
                  send_message(MSG_STRING_INT, id, "Extra INT:", getarg(i));
            }
            else if (type == MSG_FLOAT_SET) {
               new i, n = numargs();
               send_message(type, id, getfarg(2));
               for (i = 3; i < n; i++)
                  send_message(MSG_STRING_FLOAT, id, "Extra FLOAT:",
                        getfarg(i));
            }
            else if (type == MSG_STRING_SET) {
               new buf[1024], i, n = numargs();
               getsarg(2, buf, sizeof(buf));
               send_message(type, id, buf);
               for (i = 3; i < n; i++) {
                  getsarg(i, buf, sizeof(buf));
                  send_message(MSG_STRING_SET, id, "Extra STRING:", buf);
               }
            }
            else if (type == MSG_STRING_INT_SET) {
               new buf[1024], i, n = numargs();
               getsarg(2, buf, sizeof(buf));
               send_message(type, id, buf, getarg(3));
               for (i = 4; i < n; i++)
                  send_message(MSG_STRING_INT, id, "Extra INT:", getarg(i));
            }
            else if (type == MSG_STRING_FLOAT_SET) {
               new buf[1024], i, n = numargs();
               getsarg(2, buf, sizeof(buf));
               send_message(type, id, buf, getfarg(3));
               for (i = 4; i < n; i++)
                  send_message(MSG_STRING_INT, id, "Extra FLOAT:", getfarg(i));
            }
         }
      }
   }
}
